package com.java.controller.admin;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.java.mapper.AdminMapper;
import com.java.mapper.CollegeMapper;
import com.java.mapper.InClassMapper;
import com.java.mapper.LogMapper;
import com.java.mapper.StudentMapper;
import com.java.po.Admin;
import com.java.po.College;
import com.java.po.InClass;
import com.java.po.Student;
import com.java.util.LogUtil;
import com.java.util.MD5Util;
import com.java.util.PageUtil;

@Controller
@RequestMapping("/admin")
public class AdminController {
	@Autowired
	private AdminMapper adminMapper;

	@Autowired
	private StudentMapper studentMapper;

	@Autowired
	private CollegeMapper collegeMapper;

	@Autowired
	private InClassMapper inClassMapper;

	@Autowired
	private LogMapper logMapper;

	// 构造器
	private Student student = null;
	private LogUtil logUtil = null;
	private InClass inClass = null;
	private College college = null;

	public AdminController() {
		logUtil = new LogUtil();
		inClass = new InClass();
		college = new College();
		student = new Student();
	}

	/**
	 * 分页查询数据 inclass
	 * 
	 * @param page
	 * @param limit
	 * @param account
	 * @return
	 */
	@RequestMapping(value = "/findclass", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> listAllClass(@RequestParam("page") String page, @RequestParam("limit") String limit,
			@RequestParam(name = "className", defaultValue = "") String className,
			@RequestParam(name = "collegename", defaultValue = "") String collegename) {
		Map<String, Object> map = new HashMap<String, Object>();// 查询map
		int Count = inClassMapper.selectCount(null);
		PageUtil<Student> pageUtil = new PageUtil<Student>(Integer.parseInt(page), Integer.parseInt(limit), Count);
		map.put("collegename", collegename.trim());// 去除空格传值
		map.put("page", null);// 当前页数起始值
		map.put("limit", null);// 显示数量
		List<InClass> num = inClassMapper.findList(map);// 不分页查询结果
		map.put("page", pageUtil.getStartIndex());// 当前页数起始值
		map.put("limit", pageUtil.getPageSize());// 显示数量
		List<InClass> data = inClassMapper.findList(map);// 分页查询结果
		Map<String, Object> reqMap = new HashMap<String, Object>();// 返回map
		reqMap.put("code", 0);
		reqMap.put("msg", "");
		reqMap.put("count", num.size());// 显示总数目
		reqMap.put("data", data);// 显示结果
		return reqMap;
	}

	/**
	 * 添加class数据
	 * 
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "/addclass", method = RequestMethod.POST)
	@ResponseBody
	private Map<String, Object> addClass(@RequestBody HashMap<String, String> hashMap) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String className = hashMap.get("className");
			String collegeName = hashMap.get("collegeName");
			String remarks = hashMap.get("remarks");
			if (collegeName.trim().equals("") || collegeName == null) {
				map.put("status", 0);
				map.put("msg", "请选择所属学院！");
				return map;
			}
			map.put("status", 1);

			college.setCollegename(collegeName);
			College selectOne = collegeMapper.selectOne(college);
			inClass.setClassName(className);
			InClass selectOne2 = inClassMapper.selectOne(inClass);
			if (selectOne2 != null) {
				map.put("status", 0);
				map.put("msg", "该班级名称已经存在！");
				return map;
			}
			inClass.setCollegeid(selectOne.getId());
			inClass.setRemarks(remarks);
			inClass.setSnum(0);
			int result = inClassMapper.insertSelective(inClass);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "添加数据成功！");
				logMapper.insertLog("管理员", logUtil.getINSERT() + "inClass:" + className, logUtil.getSUCCESS());
			} else {
				map.put("status", 0);
				map.put("msg", "添加数据失败！");
				logMapper.insertLog("管理员", logUtil.getINSERT(), logUtil.getERROR());
			}
		} catch (Exception e) {
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			logMapper.insertLog("管理员", logUtil.getINSERT(), logUtil.getERROR());
			e.printStackTrace();
		}

		return map;
	}

	/**
	 * 删除一条inclass数据
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delInC/{id}", method = RequestMethod.DELETE)
	@ResponseBody
	private Map<String, Object> deleteinClassById(@PathVariable("id") Integer id) {
		System.out.println(id + "SSSS");
		int result = inClassMapper.deleteByPrimaryKey(id);
		Map<String, Object> map = new HashMap<String, Object>();
		if (result > 0) {
			map.put("status", 1);
		} else {
			map.put("status", 0);
		}
		return map;
	}

	/**
	 * 批量删除inclass
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/inClass/ids", method = RequestMethod.DELETE)
	@ResponseBody
	private Map<String, Object> deleteInclassByIds(@RequestParam("ids") String ids) {
		Map<String, Object> map = new HashMap<String, Object>();
		String a[] = ids.split(",");
		try {
			for (int i = 0; i < a.length; i++) {
				String id = a[i];
				inClassMapper.deleteByPrimaryKey(Integer.parseInt(id));
			}
			map.put("status", 1);
		} catch (Exception e) {
			map.put("status", 0);
			e.printStackTrace();
		}
		return map;
	}
	
	
	/**
	 * 编辑class数据
	 * 
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "/updataInClass", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> updateClass(@RequestBody HashMap<String, String> hashMap) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String id = hashMap.get("id");
			String className = hashMap.get("className");
			String collegeName = hashMap.get("collegeName");
			String remarks = hashMap.get("remarks");
			inClass.setId(Integer.parseInt(id));
//			InClass selectOne2 = inClassMapper.selectOne(inClass);
//			if (selectOne2 != null) {
//				map.put("status", 0);
//				map.put("msg", "该班级名称已经存在！");
//				return map;
//			}
			if (collegeName.trim().equals("") || collegeName == null) {
				inClass.setCollegeid(null);
			}else {
				college.setCollegename(collegeName);
				College selectOne = collegeMapper.selectOne(college);
				inClass.setCollegeid(selectOne.getId());
			}
			inClass.setClassName(className);
			inClass.setRemarks(remarks);
			inClass.setSnum(null);
			int result = inClassMapper.updateByPrimaryKeySelective(inClass);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "更新数据成功！");
				logMapper.insertLog("管理员", logUtil.getUPDATE() + "inClass:" + className, logUtil.getSUCCESS());
			} else {
				map.put("status", 0);
				map.put("msg", "更新数据失败！");
				logMapper.insertLog("管理员", logUtil.getUPDATE(), logUtil.getERROR());
			}
		} catch (Exception e) {
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			logMapper.insertLog("管理员", logUtil.getUPDATE(), logUtil.getERROR());
			e.printStackTrace();
		}

		return map;
	}


	/**
	 * 分页查询数据 College
	 * 
	 * @param page
	 * @param limit
	 * @param account
	 * @return
	 */
	@RequestMapping(value = "/findcollege", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> listAllCollege(@RequestParam("page") String page, @RequestParam("limit") String limit,
			@RequestParam(name = "collegename", defaultValue = "") String collegename) {
		Map<String, Object> map = new HashMap<String, Object>();// 查询map
		int Count = collegeMapper.selectCount(null);
		PageUtil<Student> pageUtil = new PageUtil<Student>(Integer.parseInt(page), Integer.parseInt(limit), Count);
		map.put("collegename", collegename.trim());// 去除空格传值
		map.put("page", null);// 当前页数起始值
		map.put("limit", null);// 显示数量
		List<College> num = collegeMapper.findList(map);// 不分页查询结果
		map.put("page", pageUtil.getStartIndex());// 当前页数起始值
		map.put("limit", pageUtil.getPageSize());// 显示数量
		List<College> data = collegeMapper.findList(map);// 分页查询结果
		Map<String, Object> reqMap = new HashMap<String, Object>();// 返回map
		reqMap.put("code", 0);
		reqMap.put("msg", "");
		reqMap.put("count", num.size());// 显示总数目
		reqMap.put("data", data);// 显示结果
		return reqMap;
	}

	/**
	 * 添加College数据
	 * 
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "/addcollege", method = RequestMethod.POST)
	@ResponseBody
	private Map<String, Object> addCollege(@RequestBody HashMap<String, String> hashMap) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String collegename = hashMap.get("collegename");
			String remarks = hashMap.get("remarks");
			college.setCollegename(collegename);
			College selectOne = collegeMapper.selectOne(college);
			System.out.println(selectOne + "aaa");
			if (selectOne != null) {
				map.put("status", 0);
				map.put("msg", "添加数据已存在，请重新添加！");
				return map;
			}
			college.setId(null);
			college.setRemarks(remarks);
			college.setUpdatetime(new Date());
			int result = collegeMapper.insertSelective(college);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "添加数据成功！");
				logMapper.insertLog("管理员", logUtil.getINSERT() + "college:" + collegename, logUtil.getSUCCESS());
			} else {
				map.put("status", 0);
				map.put("msg", "添加数据失败！");
				logMapper.insertLog("管理员", logUtil.getINSERT(), logUtil.getERROR());
			}
		} catch (Exception e) {
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			logMapper.insertLog("管理员", logUtil.getINSERT(), logUtil.getERROR());
			e.printStackTrace();
		}

		return map;
	}

	/**
	 * 删除一条college数据
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delC/{id}", method = RequestMethod.DELETE)
	@ResponseBody
	private Map<String, Object> deleteCollegeById(@PathVariable("id") Integer id) {
		int result = collegeMapper.deleteByPrimaryKey(id);
		Map<String, Object> map = new HashMap<String, Object>();
		if (result > 0) {
			map.put("status", 1);
		} else {
			map.put("status", 0);
		}
		return map;
	}

	/**
	 * 批量删除college
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/college/ids", method = RequestMethod.DELETE)
	@ResponseBody
	private Map<String, Object> deleteCollegeByIds(@RequestParam("ids") String ids) {
		Map<String, Object> map = new HashMap<String, Object>();
		String a[] = ids.split(",");
		try {
			for (int i = 0; i < a.length; i++) {
				String id = a[i];
				collegeMapper.deleteByPrimaryKey(Integer.parseInt(id));
			}
			map.put("status", 1);
		} catch (Exception e) {
			map.put("status", 0);
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 更新数据 college
	 * 
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateCollege", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> update(@RequestBody College college) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			college.setUpdatetime(new Date());
			int result = collegeMapper.updateByPrimaryKeySelective(college);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "更新成功！");
			} else {
				map.put("status", 0);
				map.put("msg", "更新失败！");
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * admin用户基本信息修改（更新数据）
	 * 
	 * @param student
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/update", method = RequestMethod.PUT)
	@ResponseBody
	private Map<String, Object> update(@RequestBody Admin admin, HttpServletRequest request) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			admin.setPassword(null);
			if (admin.getPhone().length() < 5) {
				map.put("status", 0);
				map.put("msg", "输入手机号有误，请重新输入！");
				return map;
			}
			if (admin.getQq().length() < 5) {
				map.put("status", 0);
				map.put("msg", "输入QQ号有误，请重新输入！");
				return map;
			}
			int result = adminMapper.updateByPrimaryKeySelective(admin);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "数据更新成功");
				logMapper.insertLog(admin.getUsername(), logUtil.getUPDATE(), logUtil.getSUCCESS());
			} else {
				map.put("status", 0);
				map.put("msg", "数据更新失败，请联系管理员！");
				return map;
			}
		} catch (Exception e) {
			logMapper.insertLog(admin.getUsername(), logUtil.getUPDATE(), logUtil.getERROR());
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			e.printStackTrace();
		}
		return map;

	}

	/**
	 * admin用户密码修改
	 * 
	 * @param student
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/uppwd", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> update(@RequestBody HashMap<String, String> hashMap, HttpServletRequest request)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String password1 = hashMap.get("password1");
			String password2 = hashMap.get("password2");
			if (!password1.equals(password2)) {
				map.put("status", 0);
				map.put("msg", "两次密码不一致，请重新输入！");
				return map;
			}
			Admin admin = (Admin) request.getSession().getAttribute("admin");
			admin.setPassword(MD5Util.md5Password(password1));
			int result = adminMapper.updateByPrimaryKeySelective(admin);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "数据更新成功");
				logMapper.insertLog(admin.getUsername(), logUtil.getUPDATE(), logUtil.getSUCCESS());
			} else {
				logMapper.insertLog(admin.getUsername(), logUtil.getUPDATE(), logUtil.getERROR());
				map.put("status", 0);
				map.put("msg", "数据更新失败，请联系管理员！");
				return map;
			}
		} catch (Exception e) {
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			e.printStackTrace();
		}
		return map;

	}

	/**
	 * 分页查询数据 student
	 * 
	 * @param page
	 * @param limit
	 * @param account
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/findstudent", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> listAll(@RequestParam("page") String page, @RequestParam("limit") String limit,
			@RequestParam(name = "username", defaultValue = "") String userName,
			@RequestParam(name = "studentid", defaultValue = "") String studentid,
			@RequestParam(name = "inclass", defaultValue = "") String inClass,
			@RequestParam(name = "state", defaultValue = "") String state) throws UnsupportedEncodingException {
		Map<String, Object> map = new HashMap<String, Object>();// 查询map
		int Count = studentMapper.selectCount(null);
		PageUtil<Student> pageUtil = new PageUtil<Student>(Integer.parseInt(page), Integer.parseInt(limit), Count);
		String username = new String(userName.getBytes("ISO-8859-1"), "utf-8");
		String inclass = new String(inClass.getBytes("ISO-8859-1"), "utf-8");
		map.put("username", username.trim());// 去除空格传值
		map.put("studentid", studentid.trim());
		map.put("inclass", inclass.trim());// 去除空格传值
		map.put("state", state.trim());
		map.put("page", null);// 当前页数起始值
		map.put("limit", null);// 显示数量
		List<Student> num = studentMapper.findList(map);// 不分页查询结果
		map.put("page", pageUtil.getStartIndex());// 当前页数起始值
		map.put("limit", pageUtil.getPageSize());// 显示数量
		List<Student> data = studentMapper.findList(map);// 分页查询结果
		Map<String, Object> reqMap = new HashMap<String, Object>();// 返回map
		reqMap.put("code", 0);
		reqMap.put("msg", "");
		reqMap.put("count", num.size());// 显示总数目
		reqMap.put("data", data);// 显示结果
		return reqMap;
	}

	/**
	 * 添加student数据
	 * 
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "/addstudent", method = RequestMethod.POST)
	@ResponseBody
	private Map<String, Object> addStudent(@RequestBody HashMap<String, String> hashMap) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String username = hashMap.get("username");
			String className = hashMap.get("className");
			inClass.setClassName(className);
			InClass inClassOne = inClassMapper.selectOne(inClass);
			if (inClassOne.getSnum()>64) {
				map.put("status", 0);
				map.put("msg", "人数已经满，请重新选择班级！");
				return map;
			}
			college.setId(inClassOne.getCollegeid());
			College collegeOne = collegeMapper.selectOne(college);
			Integer maxStudentId = studentMapper.MaxStudentId();
			student.setId(null);
			student.setStudentid(maxStudentId + 1);
			student.setUsername(username);
			student.setCollege(collegeOne.getCollegename());
			student.setInclass(className);
			student.setUpdatetime(new Date());
			student.setState(1);
			int result = studentMapper.insertSelective(student);
			if (result > 0) {
				map.put("status", 1);
				map.put("msg", "添加数据成功！");
				inClass.setSnum(inClassOne.getSnum() + 1);
				inClass.setId(inClassOne.getId());
				inClassMapper.updateByPrimaryKeySelective(inClass);
				logMapper.insertLog("管理员", logUtil.getINSERT() + "name:" + username, logUtil.getSUCCESS());
			} else {
				map.put("status", 0);
				map.put("msg", "添加数据失败！");
				logMapper.insertLog("管理员", logUtil.getINSERT(), logUtil.getERROR());
			}
		} catch (Exception e) {
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			logMapper.insertLog("管理员", logUtil.getINSERT(), logUtil.getERROR());
			e.printStackTrace();
		}

		return map;
	}

	/**
	 * 搜索框显示班级
	 * 
	 * @return
	 */
	@RequestMapping(value = "/tree", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> addStudent() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<InClass> listInClass = inClassMapper.select(null);
		map.put("csize", listInClass.size());
		String inclass = "";
		for (int i = 0; i < listInClass.size(); i++) {
			InClass inClass = listInClass.get(i);
			inclass += inClass.getClassName() + "+";
		}
		map.put("inclass", inclass);
		return map;
	}

	/**
	 * 搜索框显示学院
	 * 
	 * @return
	 */
	@RequestMapping(value = "/treeCollege", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
	@ResponseBody
	private Map<String, Object> findCollege() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<College> listCollege = collegeMapper.select(null);
		map.put("csize", listCollege.size());
		String incollege = "";
		for (int i = 0; i < listCollege.size(); i++) {
			College inCollege = listCollege.get(i);
			incollege += inCollege.getCollegename() + "+";
		}
		map.put("incollege", incollege);
		return map;
	}

	/**
	 * 删除一条student数据
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delS/{id}", method = RequestMethod.DELETE)
	@ResponseBody
	private Map<String, Object> deleteById(@PathVariable("id") Integer id) {
		student.setId(id);
		Student selectOne = studentMapper.selectOne(student);
		inClass.setClassName(selectOne.getInclass());
		InClass inClassOne = inClassMapper.selectOne(inClass);
		inClass.setId(inClassOne.getId());
		inClass.setSnum(inClassOne.getSnum() - 1);
		int result = studentMapper.deleteByPrimaryKey(id);
		Map<String, Object> map = new HashMap<String, Object>();
		if (result > 0) {
			map.put("status", 1);
			inClassMapper.updateByPrimaryKeySelective(inClass);
		} else {
			map.put("status", 0);
		}
		return map;
	}

	/**
	 * 批量删除student
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/student/ids", method = RequestMethod.DELETE)
	@ResponseBody
	private Map<String, Object> deleteByIds(@RequestParam("ids") String ids) {
		Map<String, Object> map = new HashMap<String, Object>();
		String a[] = ids.split(",");
		try {
			for (int i = 0; i < a.length; i++) {
				String id = a[i];
				student.setId(Integer.parseInt(id));
				inClass.setClassName(studentMapper.selectOne(student).getInclass());
				inClass.setId(inClassMapper.selectOne(inClass).getId());
				inClass.setSnum(inClassMapper.selectOne(inClass).getSnum() - 1);
				studentMapper.deleteByPrimaryKey(Integer.parseInt(id));
				inClassMapper.updateByPrimaryKeySelective(inClass);
			}
			map.put("status", 1);
		} catch (Exception e) {
			map.put("status", 0);
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 更新数据student
	 * 
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/updateStu", method = RequestMethod.PUT)
	@ResponseBody
	private Map<String, Object> update(@RequestBody Student student) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String username = student.getUsername();
			Integer studentid = student.getStudentid();
			String Inclass = student.getInclass();
			if (username.trim().equals("") || studentid == null) {
				map.put("status", 0);
				map.put("msg", "该用户姓名或学号不可存在空置！");
				return map;
			}
			Student s = new Student();
			Student stu1 = studentMapper.selectByPrimaryKey(student.getId());
			Student stu2 = new Student();
			stu2.setStudentid(student.getStudentid());
			Student stu3 = studentMapper.selectOne(stu2);
			if (stu3 != null) {
				if (stu3.getId() != stu1.getId()) {
					map.put("status", 0);
					map.put("msg", "学号已经存在，请换个学号！");
					return map;
				}
			}
			if (Inclass.trim().equals("") || Inclass.equals(stu1.getInclass())) {
				s.setInclass(null);
				student.setInclass(null);
			} else {
				inClass.setClassName(Inclass);
				InClass inClassOne = inClassMapper.selectOne(inClass);// 修改后班级信息
				inClass.setClassName(stu1.getInclass());
				InClass inClassTwo = inClassMapper.selectOne(inClass);// 修改前班级信息
				inClass.setId(inClassOne.getId());
				inClass.setClassName(Inclass);
				inClass.setSnum(inClassOne.getSnum() + 1);// 新的班级人数加1
				inClassMapper.updateByPrimaryKeySelective(inClass);
				inClass.setId(inClassTwo.getId());
				inClass.setClassName(stu1.getInclass());
				inClass.setSnum(inClassTwo.getSnum() - 1);// 原来班级人数减1
				inClassMapper.updateByPrimaryKeySelective(inClass);
				college = collegeMapper.selectByPrimaryKey(inClassOne.getCollegeid());
				s.setInclass(Inclass);
				s.setCollege(college.getCollegename());
				student.setCollege(college.getCollegename());
			}
			if (stu1.getReporttotime() == null) {
				s.setId(student.getId());
				s.setStudentid(studentid);
				s.setUsername(username);
				s.setUpdatetime(new Date());
				int i = studentMapper.updateByPrimaryKeySelective(s);
				if (i > 0) {
					map.put("status", 2);
					map.put("msg", "更新数据成功，该用户由于未报到，只更新了姓名，学号与班级！");
					logMapper.insertLog("管理员", logUtil.getUPDATE() + "name:" + username, logUtil.getSUCCESS());
					return map;
				} else {
					map.put("status", 0);
					map.put("msg", "更新失败！");
					return map;
				}

			}
			String password = student.getPassword();
			Integer sex = student.getSex();
			String images = student.getImages();
			Date birthdate = student.getBirthdate();
			String phone = student.getPhone();
			String address = student.getAddress();
			String qq = student.getQq();
			Integer state = student.getState();
			if (username.trim().equals("") || studentid == null || password.trim().equals("") || sex == null
					|| images.trim().equals("") || birthdate == null || phone.trim().equals("")
					|| address.trim().equals("") || qq.trim().equals("") || state == null) {
				map.put("status", 0);
				map.put("msg", "请填写内容,不可存在空置！");
				return map;
			}
			if (MD5Util.md5Password(password).equals(stu1.getPassword())) {
				student.setPassword(null);
			} else {
				student.setPassword(MD5Util.md5Password(password));
			}
			student.setUpdatetime(new Date());
			int result = studentMapper.updateByPrimaryKeySelective(student);
			if (result > 0) {
				map.put("status", 1);
				logMapper.insertLog("管理员", logUtil.getUPDATE() + "name:" + username, logUtil.getSUCCESS());
			} else {
				map.put("status", 0);
				map.put("msg", "更新失败！");
				logMapper.insertLog("管理员", logUtil.getUPDATE() + "name:" + username, logUtil.getERROR());
				return map;
			}

		} catch (Exception e) {
			map.put("status", 0);
			map.put("msg", "发送未知错误，请联系管理员！");
			logMapper.insertLog("管理员", logUtil.getUPDATE(), logUtil.getERROR());
			e.printStackTrace();
		}
		return map;
	}

}
